package utils;

import bean.User;
import org.apache.commons.beanutils.BeanUtils;

import java.util.HashMap;
import java.util.Map;

public class CreateBeanUtils {

    public static <T,K,V>  T createBeanByParams(Class<T> clazz, Map<K,V> map){


        try {
            T t = clazz.newInstance();
            BeanUtils.populate(t,map);
            return t;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void main(String[] args) {
        Map<String,String> map = new HashMap<>();

        map.put("username","龙廷雨");
        map.put("password","123");


        User user = createBeanByParams(User.class, map);
        System.out.println(user);
    }

}
